package com.nnfe.fyd.feature.inquiryPrice;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nnfe.fyd.BusKey;
import com.nnfe.fyd.R;
import com.nnfe.fyd.base.ActionBarFragment;
import com.nnfe.fyd.bean.inquiry.AutoInquiry;
import com.nnfe.fyd.feature.inquiryreport.InquiryReportAcivity;
import com.nnfe.fyd.feature.main.MainActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ----------------------------------
 * Created by xyd on 2017/5/16.
 * <p/>
 * 描  述： 询价结果
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class InquiryResultFragment extends ActionBarFragment {
    @Bind(R.id.tv_limit)
    TextView tvLimit;
    @Bind(R.id.tv_houst_value)
    TextView tvHoustValue;

    private AutoInquiry autoInquiry;


    @Override
    public Object getTitleString() {
        return "询价结果";
    }

    @Override
    public int getContentView() {
        return R.layout.fragment_inquiry_result;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        EventBus.getDefault().register(this);
        initView();
        return rootView;
    }

    @Override
    protected void initView() {
        AutoInquiryPriceActivity activity = (AutoInquiryPriceActivity) getActivity();
        autoInquiry = activity.getAutoInquiry();
        if (autoInquiry != null) {

            tvLimit.setText(autoInquiry.inquiry.getLoanLimitMin() + "~" + autoInquiry.inquiry.getLoanLimitMax());
            tvHoustValue.setText("房产估值: " + autoInquiry.fcgz + " 万元");
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(String str) {
        if (str.equalsIgnoreCase(BusKey.POST_inquiryReport)) {
            Log.e("xyd","报单提交成功");
            mContext.finish();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
        EventBus.getDefault().unregister(this);
    }

    @OnClick({R.id.btn_report, R.id.btn_my_list})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_report:  // 立即报单
                InquiryReportAcivity.lauch(mContext,autoInquiry.inquiry.id,autoInquiry.inquiry.getLoanLimitMax());
                break;
            case R.id.btn_my_list: // 我的订单
                MainActivity.launch(mContext,1);
                break;
        }
    }
}
